package xyz.xtt.exchange.utils;

import com.github.dozermapper.core.DozerBeanMapperBuilder;
import com.github.dozermapper.core.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * &#064;Title: DozerUtil.java &#064;Package &#064;Description:
 * 将一个对象的属性复制到另一个对象或者list中
 * 
 * @author hqbzl &#064;date 2024年10月17日
 * @version V1.0
 */
public class DozerUtil {
	private static final Mapper mapper = DozerBeanMapperBuilder.buildDefault();

	public static <T> List<T> transforList(List<?> sources, Class<T> clazz) {
		List<T> list = new ArrayList<>();
		if (sources == null) {
			return list;
		}
		for (Object o : sources) {
			T t = transfor(o, clazz);
			list.add(t);
		}
		return list;
	}

	public static void transfor(Object source, Object target) {
		if (source == null || target == null) {
			return;
		}
		mapper.map(source, target);
	}

	public static <T> T transfor(Object source, Class<T> target) {
		if (source == null) {
			return null;
		}
		return mapper.map(source, target);
	}

}
